<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport"
          content="target-densitydpi=device-dpi, width=device-width, initial-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="css/index1.css">

    <title>微信功能</title>
    <script type="text/javascript">
    var cText = 0;
    var cJson = 1;
    var cInt = 2;
    var appId = "wxcb60063171d6b794";
    var app_serect = "93eb0eeaf647e62285630c8932f5ff4f";
    var app_key = "L8LrMqqeGRxST5reouB0K66CaYAWpqhAVsq7ggKkxHCOastWksvuX1uvmvQclxaHoYd3ElNBrNO2DHnnzgfVG9Qs473M3DTOZug5er46FhuGofumV8H2FVR9qkjSlC5K";
    var partnerId = "1900000109";
    var traceId = "crestxu_test";
    var packageValue = "bank_type=WX&body=%E5%8D%83%E8%B6%B3%E9%87%91%E7%AE%8D%E6%A3%92&fee_type=1&input_charset=UTF-8&notify_url=http%3A%2F%2Fweixin.qq.com&out_trade_no=9d86d83f925f2149e9edb0ac3b49229c&partner=1900000109&spbill_create_ip=196.168.1.1&total_fee=1&sign=899815E4F3106CC5DCFAF76A4D16069B";

    /*---------------微信分享--------------*/

   var cbShareTextContent = function(data){
        alert("cbShareTextContent："+data);
    };
    var cbShareImageContent = function(data){
        alert("cbShareImageContent："+data);
    };
    var cbShareLinkContent = function(data){
        alert("cbShareLinkContent："+data);
    };
   	//新接口
   	function shareTextContent(){
       var type = document.getElementById("type").value;
       var jsonstr = '{"text":"这是来自AppCan平台对微信支持测试","scene":"'+type+'"}';
       uexWeiXin.shareTextContent(jsonstr, cbShareTextContent);
   	}
   	function shareImageContent(){
        var type = document.getElementById("type").value;
        var jsonstr = '{"thumbImg":"res://appcan.png","image":"res://appcan.png","scene":"'+type+'"}';
        uexWeiXin.shareImageContent(jsonstr, cbShareImageContent);
    }
   	function shareLinkContent(){
        var type = document.getElementById("type").value;
        var JsonData = '{"thumbImg":"res://icon.png","wedpageUrl":"http://www.appcan.cn","scene":"'+type+'","title":"你好,我是AppCan","description":"中国最大的移动中间键平台AppCan对微信分享的图片支持测试"}';
        //uexWeiXin.shareLinkContent(jsonstr, cbShareLinkContent);
        //var JsonData = '{"thumbImg":"res://icon.png","wedpageUrl":"http://dqmip.com","scene":1,"title":"测试测试555","description":"123"}';
	uexWeiXin.shareLinkContent(JsonData,function(error){
			if(error==0){
				 uexWindow.toast(0,5,"分享成功!",2000);
				 //closeWeixin();
			}else{
				 uexWindow.toast(0,5,"分享失败!",2000);
				 //closeWeixin();
			}
		});
    }

    /*-----------微信登录---------*/

    var code = "";
    var refreshToken = "";
    var openid = "";
    var accessToken = "";


    //新接口
    function login(){
        var params = {
            scope:"snsapi_userinfo,snsapi_base",
            state:"0902"
        };
        var data = JSON.stringify(params);
        uexWeiXin.login(data, function(data) {
            code = data.code;
            alert("callback:" + JSON.stringify(data));
        });
    }
    function getLoginAccessToken(){
        var params = {
            secret:app_serect,
            code:code,
            grant_type:"authorization_code"
        };
        var data = JSON.stringify(params);
        uexWeiXin.getLoginAccessToken(data, function(data) {
            openid = data.openid;
            accessToken = data.access_token;
            refreshToken = data.refresh_token;
            alert("callback:" + JSON.stringify(data));
        });
    }
    function getLoginRefreshAccessToken(){
        var params = {
            grant_type:"refresh_token",
            refresh_token:refreshToken
        };
        var data = JSON.stringify(params);
        uexWeiXin.getLoginRefreshAccessToken(data, function(data) {
            alert("callback:" + JSON.stringify(data));
        });
    }
    function getLoginCheckAccessToken(){
        var params = {
            access_token:accessToken,
            openid:openid
        };
        var data = JSON.stringify(params);
        uexWeiXin.getLoginCheckAccessToken(data, function(data) {
            alert("callback:" + JSON.stringify(data));
        });
    }
    function getLoginUnionID(){
        var params = {
            access_token:accessToken,
            openid:openid
        };
        var data = JSON.stringify(params);
        uexWeiXin.getLoginUnionID(data, function(data) {
            alert("callback:" + JSON.stringify(data));
        });
    }

   	/*-----------------微信支付---------------*/

    function getAccessToken(){
        uexWeiXin.getAccessToken(appId,app_serect);
    }

    function gotoPay(){
        var JsonStr = document.getElementById("showOrderInfo").innerHTML;
        var prepayid = JSON.parse(JsonStr).prepayid;
        uexWeiXin.sendPay(partnerId,prepayid,app_key,packageValue);
    }
    function registerApp(){
        alert(uexWeiXin.registerApp(appId));
    }
    function openNewWin(){
        uexWindow.open('pay', '0', "index.html", '2', '', '', 4);
        var params = {
             windowName:"pay"
        };
        uexWeiXin.setCallbackWindowName(JSON.stringify(params));
    }

    function openMiniProgram(){
        var params = {
            userName:"gh_d43f693ca31f@app",
            path:"",
            miniProgramType:"0"
        };
        uexWeiXin.openMiniProgram(JSON.stringify(params));
    }

    function openChooseInvoice(){
        uexWeiXin.openChooseInvoice({}, function(data){
            console.log("openChooseInvoice: " + JSON.stringify(data));
            alert("openChooseInvoice: " + JSON.stringify(data))
        });
    }

</script>
</head>

<body>
<div class="conbor">
    <div class="consj">
        <span>1.注册app id</span>
        <input class="btn" type="button" value="注册App" onclick="registerApp();">
        <span>2.检测是否安装微信</span>
        <input class="btn" type="button" value="检测" onclick="alert(uexWeiXin.isWXAppInstalled());">
        <span>3.获取微信itunes安装地址</span>
        <input class="btn" type="button" value="获取地址" onclick="uexWeiXin.getWXAppInstallUrl();">
        <span>4.微信分享</span>
        <span>选择分享到对话，或者朋友圈, 0：对话  1：朋友圈</span>
        <input type="text" value="0" id="type">
        <input class="btn" type="button" value="分享文本" onclick="shareTextContent();">
        <input class="btn" type="button" value="分享图片" onclick="shareImageContent();">
        <input class="btn" type="button" value="分享链接" onclick="shareLinkContent();">
        <span>---------微信登录-----------</span>

        <span>新接口</span>
        <span>login</span>
        <input class='btn' type='button' value='登录' onclick='login()'>
        <span>getLoginAccessToken</span>
        <input class='btn' type='button' value='获取accessToken' onclick='getLoginAccessToken()'>
        <span>getLoginRefreshAccessToken</span>
        <input class='btn' type='button' value='获取刷新token' onclick='getLoginRefreshAccessToken()'>
        <span>getLoginCheckAccessToken</span>
        <input class='btn' type='button' value='检验accessToken' onclick='getLoginCheckAccessToken()'>
        <span>getLoginUnionID</span>
        <input class='btn' type='button' value='获取个人信息' onclick='getLoginUnionID()'>

        <span>5.当前手机安装的微信版本是否支持微信支付</span>
        <span>返回0支持，1版本太低不支持</span>
        <input class="btn" type="button" value="判断是否支持微信支付" onclick="alert(uexWeiXin.isSupportPay())">
        <!--<span>一.获取微信支付access_token</span>
        <span>准备工作:在使用接口之前请先保证持有向微信开放平台申请得到的 appid、appsecret(长度为
           32 的字符串,用于获取 access_token)、appkey(长度为 128 的字符串,用于支付过程中生 成 app_signature)及 partnerkey(微信公众平台商户模块生成的商户密钥)。网页会在cbGetAccessTocken（）中获得。</span>
        <input class="btn" type="button" value="获取access_token" onclick="getAccessToken()">
        <span>一.获取本地微信支付access_token</span>
        <span>第一次调用getAccessTokenLocal，是没有办法获取access_token，必须通过getAccessToken获取access_token之后会把access_token存在本地，下次再使用access_token的时候就可以通过getAccessTokenLocal来获得，这么做的目的是因为微信对每天获得token的次数有限制</span>
        <input class="btn" type="button" value="获取本地access_token" onclick="uexWeiXin.getAccessTokenLocal();">
        <span>二.生成预支付订单</span>
        <span>用第一步请求的 access_token 作为参数,然后往微信开放平台接口post订单详情(需要在服务器端生成)生成预支付订单。网页会在cbGetAccessTocken（）中获得生成订单情况</span>
        <input class="btn" type="button" value="生成预支付订单" onclick="generateAdvanceOrder()">
        <span>三.调起微信支付</span>
        <span>将第二步生成的 prepayId 作为参数,调用微信 sdk 发送支付请求到微信。</span>
        <input class="btn" type="button" value="调微信支付" onclick="gotoPay()">-->
        <input class="btn" type="button" value="进入支付" onclick="openNewWin()">

        <span>6.打开微信小程序</span>

        <input class="btn" type="button" value="打开微信小程序" onclick="openMiniProgram()">

        <span>7.打开微信发票</span>

        <input class="btn" type="button" value="打开微信发票" onclick="openChooseInvoice()">

    </div>
</div>
</body>
</html>